var wait = 60;
var cce;
var sendcode = "/member/center/sendcode";
var centerindex = "/index.php/UserCenter/index";
var drawcodesave = "/index.php/payment/drawcodesave";
var cardsave = "/index.php/payment/cardsave";
var cardmove = "/index.php/payment/card_remove";
var draw = "/index.php/payment/withdrawal";
var depositlink = "/index.php/payment/deposit";
if (typeof window.IS_MOBILE !== "undefined") {
    drawcodesave = "drawcodesave";
    sendcode = "/mobile/member/center/sendcode";
    centerindex = "/mobile/member/center/index";
    drawcodesave = "/mobile/member/payment/drawcodesave";
    cardsave = "/mobile/member/payment/cardsave";
    draw = "/mobile/member/payment/draw";
    depositlink = "#/payment/deposit/1"
}
$(document).ready(function() {
    $("#card_h").click(function() {
        $(this).css("display", "none");
        $("#card_s").css("display", "block")
    });
    $(".userLink").click(function() {
        location.href = centerindex
    });
    $("#btnAmountLink").click(function() {
        location.href = depositlink
    });
    $("#get_cardcode").click(function() {
        var a = "default";
        $.get(sendcode, {
            type: 0,
            template: a
        },
        function(b) {
            if (b.success) {
                parent.showMsg("验证码已发送，请注意查收");
                wait = 60;
                clearTimeout(cce);
                downtime($("#get_cardcode"))
            } else {
                parent.showMsg("验证码发送错误，请重新发送或联系客服!")
            }
        })
    });
    $("#get_drawcode").click(function() {
        var a = "default";
        $.get(sendcode, {
            type: 0,
            template: a
        },
        function(b) {
            if (b.success) {
                parent.showMsg("验证码已发送，请注意查收");
                wait = 60;
                clearTimeout(cce);
                downtime($("#get_drawcode"))
            } else {
                parent.showMsg("验证码发送错误，请重新发送或联系客服!")
            }
        })
    });
    $("#btnCard").click(function() {
        var b = $("#bankCode option:selected").val();
        var c = $.trim($("#cardId").val());
        var a = $.trim($("#bankaddress").val());
        if (!b) {
            dialog.error("消息", "请选择银行！");
            return
        }
        if (c == "") {
            dialog.error("消息", "银行卡号不能为空！");
            return
        }
        if (a == "") {
            dialog.error("消息", "开户网点不能为空！");
            return
        }
        $(this).attr("disabled", "disabled");
        $(this).val("提交中...");
        $.ajax({
            url: cardsave,
            type: "POST",
			dataType:'json',
            data: {
                bankCode: b,
                cardId: c,
                bankaddress: a
            },
            success: function(d) {
                if (d.success) {
                    if (typeof window.IS_MOBILE !== "undefined") {
                        dialog.alert("消息", "绑定成功啦！");
                        window.location.href = "#/payment/withdrawal/?";
                        return
                    }
                    dialog.alert("消息", "绑定成功啦！", null, "/index.php/payment/withdrawal")
                } else {
                    dialog.error("消息", d.message);
                    $("#btnCard").removeAttr("disabled");
                    $("#btnCard").val("提交")
                }
            }
        })
    });
	$("#card_move").click(function() {
		 //$(this).val("解除中...");
		 
        $.ajax({
            url: cardmove,
            type: "POST",
			dataType:'json',
            data:{
				cardId:1
			},
            success: function(d) {
                if (d.success) {
                   
                    dialog.alert("消息", "解除成功啦！", null, "/index.php/payment/withdrawal")
                } else {
                    dialog.error("消息", d.message);
                   
                    $("#card_move").val("解除绑定")
                }
            }
        })
	})
    $("#btnDrawcode").click(function() {
        var a = $.trim($("#drawcode").val());
        var b = $.trim($("#redrawcode").val());
        if (a == "") {
            dialog.error("消息", "请输入提款密码！");
            return
        }
        if (a != b) {
            dialog.error("消息", "输入的密码不一致，请重新输入！");
            return
        }
        $(this).attr("disabled", "disabled");
        $(this).val("提交中...");
        $.ajax({
            url: drawcodesave,
            type: "POST",
            data: {
                drawcode: a
            },
            success: function(c) {
                if (c.success) {
                    if (typeof window.IS_MOBILE !== "undefined") {
                        dialog.alert("消息", "绑定成功啦！");
                        window.location.href = "#/payment/withdrawal/?";
                        return
                    }
                    dialog.alert("消息", "设置成功啦！", null, "/member/payment/withdrawal")
                } else {
                    dialog.error("消息", "设置失败！");
                    $("#btnDrawcode").removeAttr("disabled");
                    $("#btnDrawcode").val("提交")
                }
            }
        })
    });
    $("#btnDraw").click(function() {
        var a = $.trim($("#drawamount").val());
        var e = $.trim($("#transId").val());
       // var d = $.trim($("input[type='radio']:checked").val());
        var d = $.trim($("#cardid").val());
        var c = $.trim($("#drawcode").val());
        var r = $.trim($("#remark").val());
        if (a == "") {
            dialog.error("消息", "请输入提款金额！");
            return
        }
        if (a < MIN_AMOUNT) {
            dialog.error("消息", "提款金额不能小于" + MIN_AMOUNT + "！");
            return
        }
     
        $(this).attr("disabled", "disabled");
        $(this).val("提交中...");
        $.ajax({
            url: draw,
            type: "POST",
			dataType:'json',
            data: {
                drawamount: a,
				remark:r,
                type: 2,
            
            },
            success: function(f) {
                if (f.success) {
                    if (typeof window.IS_MOBILE !== "undefined") {
                        dialog.alert("消息", "提款信息提交成功，等待客服审核！");
                        window.location.href = "#/payment/transfer/?";
                        return
                    }
                    dialog.alert("消息", "提款信息提交成功，等待客服审核！", null, "/index.php/payment/transfer")
                } else {
                    dialog.error("消息", f.message)
                }
                $("#btnDraw").removeAttr("disabled");
                $("#btnDraw").val("提交")
            }
        })
    })
});
function downtime(a) {
    if (wait == 0) {
        a.removeAttr("disabled");
        a.val("点击获取");
        wait = 60
    } else {
        a.attr("disabled", "disabled");
        a.val("(" + wait + ")秒后重新获取验证码");
        wait--;
        cce = setTimeout(function() {
            downtime(a)
        },
        1000)
    }
};